package cn.bytecollege.dao;

import cn.bytecollege.entity.RoomCategory;

import java.util.List;

public class RoomCategoryDao extends BaseDao<RoomCategory,Integer>{
    /**
     * 查询所有的分类
     * YL
     * @param objects
     * @return
     */
    @Override
    public List<RoomCategory> find(Object... objects) {
        String sql = "SELECT ROOM_CATEGORY_ID,ROOM_CATEGORY_NAME FROM ROOM_CATEGORY WHERE DELETE_FLAG=0";
        return helper.executeQuery(sql,RoomCategory.class);
    }

    /**
     * @author LH
     * 通过分类id查询分类
     * @param roomCategoryId
     * @return
     */
    public RoomCategory findByRoomCategoryId(Integer roomCategoryId){
        String sql="SELECT room_category_name FROM `room_category` where room_category_id=?";
        List<RoomCategory> list=helper.executeQuery(sql,RoomCategory.class,roomCategoryId);
        RoomCategory roomCategory=null;
        if (list.size()>0){
            roomCategory=list.get(0);
        }
        return roomCategory;
    }
    /**
     * 查询所有的未删除的分类
     * @return
     * @author Mr.H
     */
    public List<RoomCategory> findAll(){
        String sql="select room_category_id,room_category_name from room_category where delete_flag=?";
        return helper.executeQuery(sql,RoomCategory.class,0);
    }

    /**
     * 添加新的房间分类
     * @param roomCategory
     * @return
     * @author Mr.H
     */
    @Override
    public int save(RoomCategory roomCategory) {
        String sql="insert into room_category (room_category_name,delete_flag) values(?,?)";
        Object[] objects={roomCategory.getRoomCategoryName(),roomCategory.getDeleteFlag()};
        return helper.executeUpdate(sql,objects);
    }

    /**
     * 根据房间分类名查找房间分类
     * @param categoryName
     * @return
     * @author Mr.H
     */
    public List<RoomCategory> findRoomCategoryByCategoryName(String categoryName){
        String sql="select room_category_id,room_category_name from room_category where room_category_name=?";
        return helper.executeQuery(sql,RoomCategory.class,categoryName);
    }

    /**
     * 根据ID查询分类信息
     * @param roomCategoryId
     * @return
     * @author Mr.H
     */
    public List<RoomCategory> findRoomCategoryByCategoryId(Integer roomCategoryId){
        String sql="select room_category_id,room_category_name from room_category where room_category_id=? and delete_flag=?";
        Object[] objects={roomCategoryId,0};
        return helper.executeQuery(sql,RoomCategory.class,objects);
    }

    /**
     * 更新房间分类信息
     * @param roomCategory
     * @return
     * @author Mr.H
     */
    public int update(RoomCategory roomCategory){
        String sql="update room_category set room_category_name=? where room_category_id=? and delete_flag=?";
        Object[] objects={roomCategory.getRoomCategoryName(),roomCategory.getRoomCategoryId(),0};
        return helper.executeUpdate(sql,objects);
    }

    /**
     * 根据id删除分类，逻辑删除
     * @param categoryId
     * @return
     * @author Mr.H
     */
    public int deleteCategory(Integer categoryId){
        String sql="update room_category set delete_flag=? where room_category_id=?";
        Object[] objects={1,categoryId};
        return helper.executeUpdate(sql,objects);
    }

}
